import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'
import { defineConfig } from 'vite'
import { compression } from 'vite-plugin-compression2'
import eslint from 'vite-plugin-eslint'
import { createHtmlPlugin } from 'vite-plugin-html'
import stylelint from 'vite-plugin-stylelint'

export default defineConfig({
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        // @see https://gitee.com/ant-design-vue/ant-design-vue/blob/next/components/style/themes/default.less
        modifyVars: {}
      }
    },
    modules: {
      generateScopedName: '[local]__[hash:base64:5]'
    }
  },
  resolve: {
    alias: {
      '@/': `${resolve(__dirname, 'src')}/`
    }
  },
  optimizeDeps: {
    include: [
      '@opd/g2plot-vue',
      'ant-design-vue/es/locale/zh_CN',
      'dayjs/locale/zh-cn'
    ],
    exclude: ['vue-demi']
  },
  plugins: [
    vue(),
    vueJsx(),
    compression(),
    createHtmlPlugin({
      inject: {
        data: {
          title: '后台管理系统'
        }
      },
      minify: true
    }),
    eslint({
      lintInWorker: true
    }),
    stylelint({
      lintInWorker: true
    })
  ],
  build: {
    outDir: 'dist'
  },
  server: {
    port: 7002,
    host: false,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:7001',
        changeOrigin: true
      }
    }
  }
})
